package short_semester.questionnaire_planet.response.fillResponse;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import short_semester.questionnaire_planet.pojo.*;

import java.util.LinkedList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class QuestionRecordResponse {
    Integer id;
    String title;
    String description;
    Boolean isNecessary;
    String type;
    Integer count;
    Integer grade;
    List<Integer> answer = new LinkedList<>();
    String content;
    String defaultValue;
    List<OptionRecordResponse> options = new LinkedList<>();
    
    String qtype;
    String resolution;
    String correctAnswer;
    Boolean isShowCount = false;
    Boolean isShowPercent = false;
    Boolean isShow = true;

    String relationLogic;
    //单选
    public QuestionRecordResponse(SingleChoiceQuestion question,SingleChoiceQuestionRecord record){
        id=question.getId();
        title=question.getTitle();
        description=question.getDescription();
        isNecessary=question.getIsNecessary();
        type=question.getType();
        count=question.getCount();
        if(record.getAnswer()!=null)
            answer.add(record.getAnswer());
        grade=question.getGrade();
        
        qtype=question.getQtype();
        resolution=question.getResolution();
        isShowCount = question.getIsShowCount();
        isShowPercent = question.getIsShowPercent();
        
    }
    
    //多选
    public QuestionRecordResponse(MultiChoiceQuestion question, MultiChoiceQuestionRecord record){
        id=question.getId();
        title=question.getTitle();
        description=question.getDescription();
        isNecessary=question.getIsNecessary();
        type=question.getType();
        count=question.getCount();
        answer.addAll(record.getAnswer());
        grade=question.getGrade();

        qtype=question.getQtype();
        resolution=question.getResolution();
        isShowCount = question.getIsShowCount();
        isShowPercent = question.getIsShowPercent();
    }
    
    //填空
    public QuestionRecordResponse(FillBlankQuestion question, FillBlankQuestionRecord record){
        id=question.getId();
        title=question.getTitle();
        description=question.getDescription();
        isNecessary=question.getIsNecessary();
        type=question.getType();
        count=question.getCount();
        defaultValue = question.getDefaultValue();
        content = record.getAnswer();
        grade=question.getGrade();
        
        qtype=question.getQtype();
        correctAnswer=question.getCorrectAnswer();
    }
    
    //评分题
    public QuestionRecordResponse(ScoreQuestion question,ScoreQuestionRecord record){
        id=question.getId();
        title=question.getTitle();
        description=question.getDescription();
        isNecessary=question.getIsNecessary();
        type=question.getType();
        count=question.getCount();
        if(record.getAnswer()!=null)
            answer.add(record.getAnswer());
        
        qtype=question.getQtype();
    }
}
